<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
	</head>
	<body>
		<div id="app">
			<greet @greet-event="sayHello"></greet>
		</div>
		
		<script>
			var app = Vue.createApp({
				data(){
					return {
						message:"Hello World!",
						name: "1"
					}
				},
				methods:{
					sayHello:function(name){
						alert("你好!"+name)
					}
				}
			})
			
			app.component('greet',{
				template: "<input type='text' v-model='name'/><button @click='doClick'>设置</button>",
				methods:{
					data(){
						return {
							name: ""
						}
					},
					doClick(){
						this.$emit("greetEvent", this.name)
					}
				},
				// emits: ['greetEvent']
				emits:{
					greetEvent:((name) => {
						if(name){
							return true
						}else{
							alert("请输入姓名")
							return false
						}
					})
				}
			})
			
			var vm = app.mount("#app")
		</script>
	</body>
</html>
